{include file='admin/header.html'}

<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="username" value="{$user.username}" disabled="disabled" placeholder="请输入用户名" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">不可修改</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password" value="" placeholder="留空不修改" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-inline">
            <input type="email" name="email" value="{$user.email}" placeholder="找回密码用 (可选)" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline captcha" style="width:75px;">
            <input type="text" name="captcha" value="" autocomplete="off" placeholder="验证码" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width:auto;">
            <button type="button" class="layui-btn layui-btn-primary" lay-on="verycode">获取验证码</button>
        </div>
        <div class="layui-form-mid layui-word-aux">更改邮箱用</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">昵称</label>
        <div class="layui-input-inline">
            <input type="text" name="nickname" value="{$user.nickname}" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-inline">
            <input type="text" name="phone" value="{$user.phone}" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图像</label>
        <div class="layui-input-inline">
            <input type="text" name="avatar" value="{$user.avatar}" autocomplete="off" class="layui-input upload">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-inline">
            <select name="role_id">
                <option value=""></option>
                {foreach from="$role" item="_role"}
                <option value="{$_role.id}"{if $user.role_id == $_role.id} selected{/if}>{$_role.name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="hidden" name="status" value="1">
            <input type="checkbox" name="status" value="0" lay-skin="switch"{if $user.status == 0} checked{/if}{if $user.id==1} disabled{/if} lay-text="ON|OFF">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" name="id" value="{$user.id}">
            <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
    // JS
    layui.use(['layer', 'util'], function () {
        var layer = layui.layer,
            util = layui.util,
            $ = layui.jquery;

        // 获取验证码
        util.event('lay-on', {
            verycode: function (othis) {
                var email = othis.parent().parent().find('input[name="email"]').val();
                // 倒计时函数
                var count = 60;
                othis.attr('disabled', true).addClass('layui-btn-disabled');
                var timer = setInterval(function () {
                    count--;
                    othis.text('重新发送 (' + count + ')');
                    if (count <= 0) {
                        clearInterval(timer);
                        othis.attr('disabled', false).removeClass('layui-btn-disabled').text('获取验证码');
                    }
                }, 1000);
                $.post('{$site_url}/admin/user/edit/{$user.id}.html', { email: email }, function (res) {
                    if (res.code) {
                        clearInterval(timer);
                        othis.attr('disabled', false).removeClass('layui-btn-disabled').text('获取验证码');
                        return layer.alert(res.msg, { icon: 2 });
                    }
                    layer.msg(res.msg, { icon: 1, time: 3000 });
                }, 'json');
            }
        });
    });
</script>

{include file='admin/inc/form.html'}

{include file='admin/footer.html'}